<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>harmon</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="guiro.html" title="guiro" />
    <link rel="next" href="harmon2.html" title="harmon2" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">harmon</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="guiro.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="harmon2.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="harmon"></a>
      <div class="titlepage"></div>
      <a id="IndexHarmon" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">harmon</span>
        </h2>
        <p>harmon — 
      Analyze an audio input and generate harmonizing voices in synchrony.
          </p>
      </div>
      <div class="refsect1">
        <a id="idp113758496"></a>
        <h2>Description</h2>
        <p>
      Analyze an audio input and generate harmonizing voices in synchrony.
   </p>
      </div>
      <div class="refsect1">
        <a id="idp113834992"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ares <span class="command"><strong>harmon</strong></span> asig, kestfrq, kmaxvar, kgenfreq1, kgenfreq2, imode, \
      iminfrq, iprd</pre>
      </div>
      <div class="refsect1">
        <a id="idp113837360"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>imode</em></span> -- interpreting mode for the generating frequency inputs <span class="emphasis"><em>kgenfreq1</em></span>, <span class="emphasis"><em>kgenfreq2</em></span>. 0: input values are ratios with respect to the audio signal analyzed frequency. 1: input values are the actual requested frequencies in Hz.
    </p>
        <p>
      <span class="emphasis"><em>iminfrq</em></span> -- the lowest expected frequency (in Hz) of the audio input. This parameter determines how much of the input is saved for the running analysis, and sets a lower bound on the internal pitch tracker.
    </p>
        <p>
      <span class="emphasis"><em>iprd</em></span> -- period of analysis (in seconds). Since the internal pitch analysis can be time-consuming, the input is typically analyzed only each 20 to 50 milliseconds.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp113842544"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>kestfrq</em></span> -- estimated frequency of the input.
    </p>
        <p>
      <span class="emphasis"><em>kmaxvar</em></span> -- the maximum variance (expects a value betwee 0 and 1).
    </p>
        <p>
      <span class="emphasis"><em>kgenfreq1</em></span> -- the first generated frequency.
    </p>
        <p>
      <span class="emphasis"><em>kgenfreq2</em></span> -- the second generated frequency.
    </p>
        <p>
      This unit is a harmonizer, able to provide up to two additional voices with the same amplitude and spectrum as the input. The input analysis is assisted by two things: an input estimated frequency <span class="emphasis"><em>kestfrq</em></span> (in Hz), and a fractional maximum variance <span class="emphasis"><em>kmaxvar</em></span> about that estimate which serves to limit the size of the search. Once the real input frequency is determined, the most recent pulse shape is used to generate the other voices at their requested frequencies.
    </p>
        <p>
      The three frequency inputs can be derived in various ways from a score file or MIDI source. The first is the expected pitch, with a variance parameter allowing for inflections or inaccuracies; if the expected pitch is zero the harmonizer will be silent. The second and third pitches control the output frequencies; if either is zero the harmonizer will output only the non-zero request; if both are zero the harmonizer will be silent. When the requested frequency is higher than the input, the process requires additional computation due to overlapped output pulses. This is currently limited for efficiency reasons, with the result that only one voice can be higher than the input at any one time.
    </p>
        <p>
      This unit is useful for supplying a background chorus effect on demand, or for correcting the pitch of a faulty input vocal. There is essentially no delay between input and output. Output includes only the generated parts, and does not include the input.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp113851904"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the harmon opcode. It uses the file <a class="ulink" href="examples/harmon.csd" target="_top"><em class="citetitle">harmon.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp113853760"></a>
          <p class="title">
            <strong>Example 362. Example of the harmon opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac     <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o harmon.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="oblock">instr</span> 1
 
aout <span class="opc">diskin2</span> "sing.wav", 1

kestfrq <span class="op">=</span> p4	<span class="comment">;different estimated frequency</span>
kmaxvar <span class="op">=</span> 0.1
imode   <span class="op">=</span> 1
iminfrq <span class="op">=</span> 100
iprd    <span class="op">=</span> 0.02
  
asig <span class="opc">harmon</span> aout, kestfrq, kmaxvar, kestfrq<span class="op">*</span>.5, kestfrq<span class="op">*</span>4, \
            imode, iminfrq, iprd
     <span class="opc">outs</span> (asig <span class="op">+</span> aout)<span class="op">*</span>.6, (asig <span class="op">+</span> aout)<span class="op">*</span>.6	<span class="comment">;mix dry&amp;wet signal</span>

<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="stamnt">i</span> 1 0 2.7 100
<span class="stamnt">i</span> 1 + .   200
<span class="stamnt">i</span> 1 + .   500
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp113858080"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Barry L. Vercoe</td>
          </tr>
          <tr>
            <td>M.I.T., Cambridge, Mass</td>
          </tr>
          <tr>
            <td>1997</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in version 3.47</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="guiro.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="harmon2.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">guiro </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> harmon2</td>
        </tr>
      </table>
    </div>
  </body>
</html>
